package com.biz.primus.ms.commodity.dao.po;

import com.biz.primus.base.enums.CommonStatus;
import com.biz.primus.commodity.vo.evaluation.frontend.EvaluationAddVo;
import com.biz.primus.ms.base.jpa.converter.ListStringConverter;
import com.biz.primus.ms.base.jpa.po.BaseEntity;
import lombok.Data;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

/**
 * 评论po
 *
 * @author yangzichun
 * @date 2017/2/8
 */
@Data
@Entity
@Table(name = "evaluation")
public class Evaluation extends BaseEntity implements Serializable {
    private static final long serialVersionUID = -4452195718871842524L;
    //商品
    @ManyToOne(cascade = {CascadeType.DETACH, CascadeType.REFRESH, CascadeType.MERGE}, optional = false, fetch =
            FetchType.LAZY)
    @JoinColumn(name = "product_id")
    private Product product;

    //店铺（获取店铺名）
    @Column(name = "vendor_id")
    private Long vendorId;

    //关联订单号u
    @Column(length = 50, unique = true)
    private String orderCode;

    //描述相符评分
    @Column(nullable = false)
    private Integer descriptionScore;

    //物流速度评分，用于统计店铺的总得分
    @Column(nullable = false)
    private Integer logisticsScore;

    //服务态度评分，用于统计店铺的总得分
    @Column(nullable = false)
    private Integer attitudeScore;

    //评价内容
    @Column(columnDefinition = "TEXT")
    private String content;

    //评价图片
    @Column(columnDefinition = "TEXT")
    @Convert(converter = ListStringConverter.class)
    private List<String> images;

    //会员id
    private Long memberId;

    //是否在前台显示评论,默认DISABLE（value = 2）不显示
    @Column(nullable = false)
    @Convert(converter = CommonStatus.Converter.class)
    private CommonStatus commonStatus = CommonStatus.DISABLE;

    /**
     * 拷贝评价 vo 的数据到评价 po
     *
     * @param evaluationAddVo
     */
    public void fromEvaluationAddVo(EvaluationAddVo evaluationAddVo) {
        this.setMemberId(evaluationAddVo.getMemberId());
        this.setImages(evaluationAddVo.getImages());
        this.setLogisticsScore(evaluationAddVo.getLogisticsScore());
        this.setAttitudeScore(evaluationAddVo.getAttitudeScore());
        this.setOrderCode(evaluationAddVo.getOrderCode());
        this.setDescriptionScore(evaluationAddVo.getDescriptionScore());
        this.setContent(evaluationAddVo.getContent());
    }

}
